package cn.group01.git.controller;

import cn.group01.git.annotations.LogOperation;
import cn.group01.git.common.Operation;
import cn.group01.git.common.ResponseResult;
import cn.group01.git.dto.AgentDTO;
import cn.group01.git.entity.Agent;
import cn.group01.git.service.AgentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author: 加瓦程序员小鹏
 * @Date: 2023/7/11
 * @Description: 代理商控制层
 */

@RestController
@RequestMapping("agent")
public class AgentController {

    @Autowired
    private AgentService agentService;

    // 数据分页展示 + 查询
    @GetMapping("list")
    @LogOperation(description = Operation.SELECT,model = "代理商模块")
    public ResponseResult getList(AgentDTO agentDTO){
        System.out.println("========数据分页展示 + 查询=======");
        return agentService.getList(agentDTO);
    }
    // 出库模块下拉框用到的
    @GetMapping("selectList")
    @LogOperation(description = Operation.OTHER,model = "代理商模块")
    public List<Agent> selectList(){
        System.out.println("========代理商数据信息=======");
        return agentService.selectList();
    }
    // 添加代理商
    @PostMapping("add")
    @LogOperation(description = Operation.ADD,model = "代理商模块")
    public ResponseResult addAgent(@RequestBody Agent agent){
        return agentService.addAgent(agent);
    }

    // 根据id查询代理商（编辑时数据回显）
    @GetMapping("getById")
    @LogOperation(description = Operation.OTHER,model = "代理商模块")
    public Agent getById (String agentId){

        return agentService.getById(agentId);
    }

    // 编辑代理商
    @PostMapping("edit")
    @LogOperation(description = Operation.UPDATE,model = "代理商模块")
    public ResponseResult editAgent(@RequestBody Agent agent){
        return agentService.editAgent(agent);
    }

    // 删除代理商
    @GetMapping("delete")
    @LogOperation(description = Operation.DELETE,model = "代理商模块")
    public ResponseResult delete (Integer[] ids){
        return agentService.delete(ids);
    }

    // 代理商批量导入
    @PostMapping("batch")
    @LogOperation(description = Operation.ADD,model = "代理商批量导入")
    public ResponseResult addAgents(MultipartFile file){
        return agentService.batchAdd(file);
    }


}
